/*
 * Main.fx
 *
 * Created on 08/05/2009, 18:45:46
 */

package webooksfx_desktop;

import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.stage.AppletStageExtension;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import webooksfx.controller.*;
import webooksfx.view.*;
import webooksfx_desktop.view.BorderStage;
import webooksfx_desktop.view.DesktopDetailView;
import webooksfx_desktop.view.DesktopLoadingView;
import webooksfx_desktop.view.DesktopSearchView;

/**
 * @author Administrador
 */

 /*============================================================================================
 GENERAL PROFILE
 ============================================================================================*/
 //Generamos las controladoras
def loadingControl: LoadingControl = LoadingControl {};
def detailControl: DetailControl = DetailControl {};
def searchControl: SearchControl = SearchControl {};
loadingControl.initControl(searchControl);
detailControl.initControl(searchControl);
searchControl.initControl(loadingControl, detailControl);

/*============================================================================================
 DESKTOP PROFILE
 ============================================================================================*/
var stageWidth: Integer = 600;
def stageHeight: Integer = 650;
def stageTitle: String  = "Webooks Desktop";

def loadView: LoadingView = DesktopLoadingView {
	loadingControl: loadingControl;
};
def searchView: SearchView = DesktopSearchView{
	searchControl: searchControl;
	visible: bind searchControl.visibilidad
};
def detailView: DetailView = DesktopDetailView{
	detailControl: detailControl;
	visible: bind searchControl.visibilidad
};
//============================================================================================

/*============================================================================================
 GENERAL PROFILE
 ============================================================================================*/
 //Asignamos las vistas a las controladoras
loadingControl.view = loadView;
searchControl.view = searchView;
detailControl.view = detailView;
//============================================================================================

//Generamos la variable encargada de mostrar y ocultar las pantallas
var visibilidad : Boolean = false;

var stage: Stage = Stage {
    title: stageTitle;
    width: bind if ( searchControl.visibilidad ) stageWidth else 700;
    height: stageHeight;
	style: StageStyle.TRANSPARENT;
	resizable: false;
	extensions: AppletStageExtension {
		shouldDragStart: function(e: MouseEvent): Boolean {
			e.primaryButtonDown;
		}
    }
    scene: Scene {
		fill: Color.TRANSPARENT;
		content: [
			Rectangle {
				width: stageWidth
				height: stageHeight
				fill: Color.BLACK
				arcHeight: 30
				arcWidth: 28
				opacity: 0.7
				visible: bind searchControl.visibilidad
			},
			ImageView {
				translateX: 50
				translateY: 255
				opacity: .8
				image: Image {
					url: "{__DIR__}view/images/logo.png"
				}
				visible: bind searchControl.visibilidad
			}
			Group{
				translateY: 30
				content: [
					loadView,
					searchView,
					detailView
				]
			},
			BorderStage{
				offsetY: 30
				width: stageWidth
				height: stageHeight
				actionClose: function() : Void{
					stage.close();
				}
				visible: bind searchControl.visibilidad
			}
        ]
    }
}

loadingControl.inicializarApp();
(loadView as DesktopLoadingView).closeAction = function() : Void {
	stage.close();
}